-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix UMD wrapper issues and refine wrappers #2600
Conversation
…ion, only check for self in the UMD-IIFE case
Was there any reason there for the assignment in |
The reason for doing it in a little more complicated way is that in most situations, global will be used more than once and it was getting complicated to check how often global is accessed and implement two different versions for each possible access. Getting this right would have meant basically counting all accesses to global first before actually writing anything. Not impossible but quite complicated. |
For reference, this is what the wrapper will look like in a complicated scenario with a (function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('external1'), require('external2')) :
typeof define === 'function' && define.amd ? define(['exports', 'external1', 'external2'], factory) :
(global = global || self, (function () {
var current = global.my && global.my.nested && global.my.nested.bundle;
var exports = (global.my = global.my || {}, global.my.nested = global.my.nested || {}, global.my.nested.bundle = {});
factory(exports, global.external1, global.external2);
exports.noConflict = function () { global.my.nested.bundle = current; return exports; };
}()));
}(this, function (exports, external1, external2) { 'use strict';
const x = external1.value1 || external2.value2;
exports.x = x;
Object.defineProperty(exports, '__esModule', { value: true });
})); |
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Description
With the recent changes to the UMD wrapper, several bugs were introduced. This addresses this and includes a thorough test suite of 240 tests (of which 84 were broken, some event before the latest refactorings!) that actually runs the UMD wrapper with different combinations of options and different scenarios:
options:
environments:
tests:
All tests are green now and the wrapper could be further refined. Moreover,
this
will now have precedence overself
in iife mode and the check has been moved into the wrapper code, e.g.A similar treatment is done for the IIFE wrappers.